<template>
	<view class="page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<pageTxt>
			<z-paging ref="paging" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<view class="navbar-box">
						<u-navbar title="现场反馈" :autoBack="true" :fixed="false"></u-navbar>
					</view>
				</template>
				<view class="add-content ios">
					<u--form labelPosition="top" :model="formData" ref="uForm" labelWidth="auto">
						<view class="form-box">
							<u-form-item labelPosition="top" labelWidth="100%" required label="是否需要集采订货" borderBottom>
								<u-radio-group v-model="formData.is_order_goods" placement="row">
									<u-radio label="需要" :name="1"></u-radio>
									<u-radio label="不需要" :name="2"></u-radio>
								</u-radio-group>
							</u-form-item>

							<u-form-item labelPosition="top" labelWidth="100%" required label="订单需求(明细)" borderBottom v-if="formData.is_order_goods == 1">
								<u--textarea
									disableDefaultPadding
									v-model="formData.order_demand"
									border="none"
									placeholder="请输入订单需求(明细)"
									:placeholderStyle="{ fontSize: '13.5px', color: '#BFC4CC' }"
								></u--textarea>
							</u-form-item>

							<u-form-item labelPosition="top" labelWidth="100%" required label="工长" borderBottom @click="showSelect('foremanShow')">
								<u-input
									:value="formData.foreman_item.name"
									disabled
									disabledColor="#ffffff"
									placeholder="请选择工长"
									border="none"
									suffixIcon="arrow-right"
								></u-input>
							</u-form-item>

							<u-form-item labelPosition="top" labelWidth="100%" required label="现场核实照片">
								<file-upload :typeList="['m﻿4a', 'mp3', 'zip', 'rar']" @afterRead="afterRead" @delete="deletePic"></file-upload>
							</u-form-item>
						</view>
					</u--form>
				</view>
				<view class="footer ios">
					<u-button
						text="提交"
						@click="submit"
						customStyle="width: 702rpx;height: 88rpx;background: #3B75FF;border-radius: 16rpx;font-weight: 500;font-size: 28rpx;color: #FFFFFF;margin:20rpx 24rpx;"
					></u-button>
				</view>
			</z-paging>
		</pageTxt>

		<!-- 工长 -->
		<u-picker
			:show="foremanShow"
			:columns="foremanList"
			keyName="name"
			@confirm="confirm($event, 'foreman_item')"
			closeOnClickOverlay
			@close="close"
			@cancel="close"
			confirmColor="#3B75FF"
		></u-picker>

		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
export default {
	data() {
		return {
			loading: false,
			formData: {
				id: '',
				is_order_goods: 1,
				order_demand: '',
				site_file: [],
				foreman_item: ''
			},
			foremanList: [],
			foremanShow: false
		};
	},
	onLoad(e) {
		this.formData.id = e.id;

		this.getList();
	},
	methods: {
		showSelect(type) {
			this[type] = true;
		},
		close() {
			this.foremanShow = false;
		},
		confirm(e, type) {
			console.log(e, type, 'confirm');
			this.formData[type] = e.value[0];
			this.close();
		},

		afterRead(files) {
			files.map((item) => {
				let obj = {
					path: item.url
				};
				this.formData.site_file.push(obj);
				console.log(this.formData.site_file, 'afterRead');
			});
		},
		deletePic(e) {
			console.log(e, 'deletePic');
			this.formData.site_file.splice(e.index, 1);
		},
		submit() {
			let formData = this.formData;
			if (formData.is_order_goods == 1 && !formData.order_demand) {
				this.$refs.uToast.show({
					message: '请输入订单需求(明细)'
				});
				return;
			}
			if (formData.site_file.length == 0) {
				this.$refs.uToast.show({
					message: '请上传现场核实照片'
				});
				return;
			}
			uni.showLoading({
				mask: true
			});
			// 上传文件
			this.$upload(formData.site_file).then((res) => {
				console.log(res, 'zxxx');

				this.$hApi
					.wxFeedbackSiteSituation({
						after_sales_id: formData.id,
						is_order_goods: formData.is_order_goods,
						order_demand: formData.is_order_goods == 1 ? formData.order_demand : '',
						foreman_id: formData.foreman_item.id,
						foreman_name: formData.foreman_item.name,
						site_file: res.arrResult
					})
					.then((res) => {
						console.log(res, 'wxFeedbackSiteSituation');
						uni.hideLoading();
						if (res.code == 200) {
							setTimeout(() => {
								var currentPages = getCurrentPages()[getCurrentPages().length - 2]
								if (currentPages) {
									uni.navigateBack({
										delta: 1
									});
								} else {
									uni.reLaunch({
										url: '/pages/index/index'
									});
								}
							}, 500);
						}
						uni.showToast({
							title: res.code == 200 ? '操作成功' : res.message,
							icon: res.code == 200 ? 'success' : 'error'
						});
					});
			});
		},

		getList() {
			// 获取工长
			this.$hApi
				.getForemanList({
					page: 1,
					num: 999,
					show_deactivate: 2
				})
				.then((res) => {
					console.log(res, '获取工长');
					if (res.code == 200) {
						this.foremanList = [res.data.list];
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped></style>
